#ifndef _MASTER_H_
#define _MASTER_H_

#include "EventProcessor.h"
#include "EventProcessorImp.h"
#include "Message.h"
#include "DistributedCounter.h"
#include "Worker.h"
#include "TwoWayList.h"
#include <vector>

using namespace std;

#define BUFFER_SIZE 100

//#define NUM_WORKERS 10

class MasterImp : public EventProcessorImp {
private:

  vector<int> buffer;
  
  bool generatorsDone;

  int current;	
  
  long int sum;

  int numWorkers;	

  TwoWayList <EventProcessor> myWorkers;

  void CreateWorker();	

  MasterImp(void);
  	
  MESSAGE_HANDLER_DECLARATION(PushNumber);
	
  MESSAGE_HANDLER_DECLARATION(GenDone);

  MESSAGE_HANDLER_DECLARATION(SumDone);

  MESSAGE_HANDLER_DECLARATION(WorkerDone);

  MESSAGE_HANDLER_DECLARATION(Die);

  friend class Master;
};

// Interface class
class Master : public EventProcessor {
public:
  Master(void);
};

inline Master::Master(void){
	evProc = new MasterImp();
}

#endif 
